package com.itheima.mapper;

import com.itheima.pojo.Dept;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 使用@Mapper注解标记该接口为MyBatis的Mapper接口
 * MyBatis会自动扫描并创建该接口的动态代理实现
 */
@Mapper
public interface DeptMapper {
    //  查询所有部门
//    @Results({
//            @Result(id = true, column = "id", property = "id"),
//            @Result(column = "name", property = "name"),
//            @Result(column = "create_time", property = "createTime"),
//            @Result(column = "update_time", property = "updateTime")
//    })
    //@Select("select id,name,create_time as 'createTime', update_time as 'updateTime' from dept")
    @Select("select * from dept")
    List<Dept> list();

    //  保存部门
    @Insert("insert into dept(name,create_time,update_time) values (#{name},#{createTime},#{updateTime})")
    void save(Dept dept);
    //     根据id删除部门
    @Delete("delete  from dept where id =#{id}")
    void deleteById(Integer id);
    //     根据id查询部门
    @Select("select  * from dept where id=#{id}")
    Dept getById(Integer id);
    //     更新部门
    @Update("update dept set name=#{name},create_time=#{createTime}, update_time=#{updateTime} where id=#{id}")
    void update(Dept dept);
}
